package cn.op.portal.category.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.op.portal.category.dao.CategoryDao;
import cn.op.portal.category.domain.Category;
import cn.op.portal.common.vo.Page;
import cn.op.portal.towel.dao.TowelDao;
import cn.op.portal.towel.domain.Towel;

@Service()
@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.DEFAULT)
public class CategoryService{
	@Resource
	private CategoryDao categoryDao;
	
	public void add(Category c) {
		String sql = "insert into t_category(name, description) values(?,?)";
		categoryDao.add(sql, c.getName(),c.getDescription());
	}
	
	public void deleteById(int id) {
		String sql = "delete from t_category where id=?";
		categoryDao.delete(sql, id);
	}
	
	public Category findById(int id) {
		String sql = "select id, name, description from t_category where id=?";
		return categoryDao.findById(sql, id);
	}
	
	public Page findPage(int pageNum, int pageSize, Object...values) throws Exception{
		String sql = "select id,name,description from t_category";
		return categoryDao.findPage(sql, pageNum, pageSize, values);
	}

	public void update(Category c) {
		String sql = "update t_category set name=?, description=? where id=?";
		categoryDao.update(sql,c.getName(),c.getDescription(),c.getId());
	}

	public CategoryDao getCategoryDao() {
		return categoryDao;
	}

	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	public List<Category> getAll() {
		String sql = "select id,name,description from t_category";	
		return categoryDao.getAll(sql);
	}
}
